package pe.com.fastfood4.rie.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pe.com.fastfood4.rie.model.Plato;
import pe.com.fastfood4.rie.model.Reserva;
import pe.com.fastfood4.rie.service.PlatoService;
import pe.com.fastfood4.rie.service.ReservaService;

/**
 * FacturarReservaFormController.java
 * es llamado desde facturarReservaResultado.jsp; obtiene una reserva por idReserva y sus detalles (platos);
 * y se las pasa a facturarReservaForm.jsp
 * @author grupo 06 - upc_dew 2010
 * @since 1.0
 * @see ifernandez.aq@gmail.com
 */
public class FacturarReservaFormController implements Controller {

    private ReservaService reservaService;
    private PlatoService platoService;

    public void setReservaService(ReservaService reservaService) {
        this.reservaService = reservaService;
    }

    public void setPlatoService(PlatoService platoService) {
        this.platoService = platoService;
    }

    protected final Log logger = LogFactory.getLog(getClass());

    public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse res) throws Exception {
        String idReserva = req.getParameter("idReserva");
        String fecha = req.getParameter("fecha");
        logger.info("idReserva = " + idReserva);
        logger.info("fecha = " + fecha);

        Reserva reserva = reservaService.getReservaPorId(idReserva);
        logger.info("reserva = " + reserva);

        List<Plato> platos = platoService.getPlatosPorIdReserva(idReserva);

        Map<String, Object> myModel = new HashMap<String, Object>();
        myModel.put("reserva", reserva);
        myModel.put("platos", platos);
        
        return new ModelAndView("facturarReservaForm", "model", myModel);
    }
}